package com.xiaomili.halfsugar.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xiaomili.halfsugar.R;
import com.xiaomili.halfsugar.bean.ListDetailBean;

/**
 * Created by WangQi on 2016/7/23.
 */
public class ListDetailRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private ListDetailBean.DataBean mData;
    private static final int NORMAL_TYPE = 0;
    private static final int ORIGINAL_TYPE = 1;

    public ListDetailRecyclerViewAdapter(Context context, ListDetailBean.DataBean data) {
        this.mContext = context;
        this.mData = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        if (viewType == NORMAL_TYPE) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.listdetail_recyclerview_item, parent, false);
            return new NormalViewHolder(view);
//        }
//        View view = LayoutInflater.from(mContext).inflate(R.layout., parent, false);
//        return new OriginalViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (getItemViewType(position) == NORMAL_TYPE) {
//            holder.tv_title.setText(mList.get(position).getTitle());
//            holder.tv_desc.setText(mList.get(position).getDesc());
//            Picasso.with(mContext).load(mList.get(position).getPics().get(0).getUrl()).into(holder.iv_img1);
//            Picasso.with(mContext).load(mList.get(position).getPics().get(1).getUrl()).into(holder.iv_img2);
//            holder.tv_product_name.setText(mList.get(position).getTitle());
//            Picasso.with(mContext).load(mList.get(position).getUrl()).into(holder.iv_product_img);
//            holder.tv_product_price.setText(mList.get(position).getPrice());
//            holder.tv_likes.setText(mList.get(position).getLikes());
        }
    }

    @Override
    public int getItemViewType(int position) {
        String type = mData.getType();
        if (type.equals("")) {
            return NORMAL_TYPE;
        }
        return ORIGINAL_TYPE;
    }

    @Override
    public int getItemCount() {
        if (mData.getType().equals("")) {
            return mData.getProduct_list().size();
        }
        return mData.getContent_list().size();
    }

    class NormalViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_title, tv_desc, tv_product_name, tv_product_price, tv_likes;

        private ImageView iv_img1, iv_img2, iv_product_img;

        public NormalViewHolder(View itemView) {
            super(itemView);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title);
            tv_desc = (TextView) itemView.findViewById(R.id.tv_desc);
            tv_product_name = (TextView) itemView.findViewById(R.id.tv_product_name);
            tv_product_price = (TextView) itemView.findViewById(R.id.tv_product_price);
            tv_likes = (TextView) itemView.findViewById(R.id.tv_likes);
            iv_img1 = (ImageView) itemView.findViewById(R.id.iv_img1);
            iv_img2 = (ImageView) itemView.findViewById(R.id.iv_img2);
            iv_product_img = (ImageView) itemView.findViewById(R.id.iv_product_img);

        }
    }

    class OriginalViewHolder extends RecyclerView.ViewHolder {

        public OriginalViewHolder(View itemView) {
            super(itemView);
        }
    }
}
